package com.ponhu.ea2.query;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ponhu.ea2.common.basic.model.BaseCriteria;
import com.ponhu.ea2.support.validation.annotions.ValidateEnumValue;
import com.ponhu.ea2.support.validation.annotions.ValidateExpression;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 选品查询条件对象
 *
 * @author Wang
 * @date 2021/12/10 2:52 下午
 */
@ApiModel("选品查询条件对象")
@Data
@Accessors(chain = true)
@ValidateExpression.List({
        @ValidateExpression(expression = "(createTimeStart == null or createTimeStart == '' or createTimeEnd == null or createTimeEnd == '' or (createTimeStart == null and createTimeEnd == null)) or  (createTimeStart != null and createTimeEnd != null and createTimeStart != '' and createTimeEnd != '' and createTimeStart <= createTimeEnd)", message = "创建结束时间必须大于创建开始时间"),
        @ValidateExpression(expression = "(costPriceMin == null or costPriceMax == null or (costPriceMin == null and costPriceMax == null)) or (costPriceMin !=null and costPriceMax != null and costPriceMin <= costPriceMax)", message = "货品成本最小值不能大于最大值"),
        @ValidateExpression(expression = "(warehousePriceMin == null or warehousePriceMax == null or (warehousePriceMin == null and warehousePriceMax == null))or (warehousePriceMin !=null and warehousePriceMax != null and warehousePriceMin <= warehousePriceMax)", message = "入库价最小值不能大于最大值"),
        @ValidateExpression(expression = "(salesPriceMin == null or salesPriceMax == null or (salesPriceMin == null and salesPriceMax == null))or (salesPriceMin !=null and salesPriceMax != null and salesPriceMin <= salesPriceMax)", message = "含税销售价最小值不能大于最大值"),
        @ValidateExpression(expression = "(supplyPriceMin == null or supplyPriceMax == null or (supplyPriceMin == null and supplyPriceMax == null))or (supplyPriceMin !=null and supplyPriceMax != null and supplyPriceMin <= supplyPriceMax)", message = "含税供货价最小值不能大于最大值"),
        @ValidateExpression(expression = "(salesStockNumMin == null or salesStockNumMax == null or (salesStockNumMin == null and salesStockNumMax == null))or (salesStockNumMin !=null and salesStockNumMax != null and salesStockNumMin <= salesStockNumMax)", message = "可售库存最小值不能大于最大值"),
        @ValidateExpression(expression = "(realStockNumMin == null or realStockNumMax == null or (realStockNumMin == null and realStockNumMax == null))or (realStockNumMin !=null and realStockNumMax != null and realStockNumMin <= realStockNumMax)", message = "实物库存最小值不能大于最大值"),
        @ValidateExpression(expression = "(brandIdList == null or brandIdList.size() == 0) or ( brandIdList != null and brandIdList.size() >0  and seriesName == null and modelName == null)", message = "选择品牌时，系列名称与型号名称必须为空"),
        @ValidateExpression(expression = "(categoryId != null) or ((categoryId == null or categoryId == 0) and propertyColourId == null and propertyMaterialId == null)", message = "未选择品类时，颜色与材质必须为空"),
        @ValidateExpression(expression = "(isSales == null or isSales) or (!isSales and (salesStockNumMin == null or salesStockNumMin == 0) and (salesStockNumMax == null or salesStockNumMax == 0))", message = "是否可售为否时，可售数最小值与最大值不得大于0"),
        @ValidateExpression(expression = "(inventoryCode == null and inventoryCodeList != null) or (inventoryCode != null and inventoryCodeList == null) or (inventoryCode == null and inventoryCodeList == null)", message = "货品编码与货品编码列表只能选择一个"),
        @ValidateExpression(expression = "(firstCategoryId == null and secondCategoryId ==null and categoryId == null) or (firstCategoryId != null and secondCategoryId ==null and categoryId == null) or (firstCategoryId == null and secondCategoryId !=null and categoryId == null) or (firstCategoryId == null and secondCategoryId ==null and categoryId != null)", message = "品类ID只能选择一个级别")
})

public class PickInventoryQuery extends BaseCriteria implements Serializable {
    private static final long serialVersionUID = -2583107711136106894L;

    @JsonIgnore
    private Long inventoryId;

    /**
     * 用户KPI货品权限(0:有权限;1:无权限)
     */
    @JsonIgnore
    private String pickInventoryRule;

    /**
     * 物料相关
     */
    @ApiModelProperty("物料编码")
    private String materialCode;


    @ApiModelProperty("品牌ID列表")
    private List<@Min(value = 1, message = "品牌ID必须大于0") @NotNull(message = "品牌ID不能为空") Long> brandIdList;

    @Min(value = 1, message = "一级品类Id必须大于0")
    @ApiModelProperty("一级品类Id")
    private Long firstCategoryId;

    @Min(value = 1, message = "二级品类Id必须大于0")
    @ApiModelProperty("二级品类Id")
    private Long secondCategoryId;

    @Min(value = 1, message = "三级品类Id必须大于0")
    @ApiModelProperty("三级品类Id")
    private Long categoryId;

    @JsonIgnore
    private List<Long> categoryIds;

    @ApiModelProperty("成色ID")
    private List<@Min(value = 1, message = "成色ID必须大于0") @NotNull(message = "成色ID不能为空") Integer> quantityIdList;

    @Min(value = 1, message = "系列ID必须大于0")
    @ApiModelProperty("系列ID")
    private Long seriesId;
    @ApiModelProperty("系列名称")
    private String seriesName;
    @ApiModelProperty("型号Id")
    private Long modelId;
    @ApiModelProperty("型号名称")
    private String modelName;

    /**
     * 货品相关
     */
    @ApiModelProperty("货品编码(模糊查询)")
    private String inventoryCode;

    @ApiModelProperty("货品编码列表(导出)")
    private List<@NotEmpty(message = "货品编码不能为空") String> inventoryCodeList;

    @ApiModelProperty("货品名称")
    private String inventoryName;
    @ApiModelProperty("货品创建开始时间(格式：yyyy-MM-dd)")
    private String createTimeStart;
    @ApiModelProperty("货品创建结束时间(格式：yyyy-MM-dd)")
    private String createTimeEnd;

    @ValidateEnumValue(intValues = {1, 2}, message = "是否二奢值必须为1或2", required = false)
    @ApiModelProperty("是否二奢(null:全部；1：二奢；2：标品)")
    private Integer isSecondhand;

    @Min(value = 0, message = "货品成本最小必须大于等于0")
    @ApiModelProperty("货品成本最小")
    private BigDecimal costPriceMin;

    @Min(value = 0, message = "货品成本最大必须大于等于0")
    @ApiModelProperty("货品成本最大")
    private BigDecimal costPriceMax;

    @Min(value = 0, message = "入库价最小必须大于等于0")
    @ApiModelProperty("入库价最小")
    private BigDecimal warehousePriceMin;

    @Min(value = 0, message = "入库价最大必须大于等于0")
    @ApiModelProperty("入库价最大")
    private BigDecimal warehousePriceMax;

    @Min(value = 0, message = "含税销售价最小必须大于等于0")
    @ApiModelProperty("含税销售价最小")
    private BigDecimal salesPriceMin;

    @Min(value = 0, message = "含税销售价最大必须大于等于0")
    @ApiModelProperty("含税销售价最大")
    private BigDecimal salesPriceMax;

    @Min(value = 0, message = "含税供货价最小必须大于等于0")
    @ApiModelProperty("含税供货价最小")
    private BigDecimal supplyPriceMin;

    @Min(value = 0, message = "含税供货价最大必须大于等于0")
    @ApiModelProperty("含税供货价最大")
    private BigDecimal supplyPriceMax;

    @ApiModelProperty("中检状态(null全部，1未中检，2中检已通过，3中检未通过，4中检无结果)")
    private Integer ccicStatus;

    @ApiModelProperty("适用人群(1所有人,2男士,3女士)")
    private List<@ValidateEnumValue(intValues = {1, 2, 3}, message = "适用人群必须为1所有人,2男士,3女士") Integer> applyCrowdIds;

    /**
     * 货品属性相关
     */
    @Min(value = 1, message = "颜色属性值ID必须大于0")
    @ApiModelProperty("颜色属性值ID")
    private Long propertyColourId;

    @Min(value = 1, message = "材质属性值ID必须大于0")
    @ApiModelProperty("材质属性值ID")
    private Long propertyMaterialId;
    @ApiModelProperty("包号属性")
    private String propertyBagNo;
    @ApiModelProperty("表号属性")
    private String propertyWatchNo;

    /**
     * 库存相关
     */

    @Min(value = 0, message = "可售库存数最小必须大于等于0")
    @ApiModelProperty("可售库存数最小")
    private Integer salesStockNumMin;

    @Min(value = 0, message = "可售库存数最大必须大于等于0")
    @ApiModelProperty("可售库存最大")
    private Integer salesStockNumMax;

    @Min(value = 0, message = "实物库存最小必须大于等于0")
    @ApiModelProperty("实物库存最小")
    private Integer realStockNumMin;

    @Min(value = 0, message = "实物库存最大必须大于等于0")
    @ApiModelProperty("实物库存最大")
    private Integer realStockNumMax;

    @ApiModelProperty("是否可售")
    private Boolean isSales;
    @ApiModelProperty("仓库位置")
    private List<@NotEmpty(message = "仓库编码不能为空") String> warehouseCodeList;

    /**
     * 采购中心相关
     */
    @ApiModelProperty("入库方式ID数组")
    private List<@NotNull(message = "入库方式不能为空") Integer> warehouseWayList;
    @ApiModelProperty("采购类型ID")
    private Integer purchaseTypeId;
    @ApiModelProperty("采购渠道ID")
    private Integer purchaseChannelId;
    @ApiModelProperty("供应商名称")
    private String vendorName;
    @ApiModelProperty("备注")
    private String remarks;
    @ApiModelProperty(value = "检测结果")
    private String maintainResult;

    @Valid
    @ApiModelProperty("排序参数")
    private OrderModel orderModel;
}

